<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" label-width="68px">
      <el-row>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
            <el-input v-model="queryParams.params.projectName" placeholder="请输入" clearable
              @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4" style="margin-left: 20px;">
          <el-form-item label="员工姓名" prop="staffName">
            <el-input v-model="queryParams.staffName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4" style="margin-left: 20px;">
          <el-form-item label="身份证号" prop="staffIdcard">
            <el-input v-model="queryParams.staffIdcard" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4" style="margin-left: 20px;">
          <el-form-item label="员工编号" prop="staffNo">
            <el-input v-model="queryParams.staffNo" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row :gutter="20">
      <!--人员数据-->
      <el-col :span="24" :xs="24">
        <el-table v-loading="loading"  :data="CldStaffList" row-key="staffId" @selection-change="handleSelectionChange" border>
          <el-table-column v-if="isMultiple" type="selection" width="55" align="center" :reserve-selection="true" />
          <el-table-column v-if="isProject" label="项目区域" align="center" prop="projectRegion">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
            </template>
          </el-table-column>
          <el-table-column v-if="isProject" label="项目名称" align="center" prop="projectName" />
          <el-table-column label="员工姓名" align="center" prop="staffName" />
          <el-table-column label="职别" align="center" prop="jobName" />
          <el-table-column label="身份证" align="center" prop="staffIdcard" />
          <el-table-column v-if="isProject" label="岗位" align="center" prop="projectPostName">
            <template slot-scope="scope">
              <dict-tag :options="dict.type.cld_project_post" :value="scope.row.projectPostName" />
            </template>
          </el-table-column>
          <el-table-column label="年龄" align="center">
            <template slot-scope="scope">
              {{ calculateAge(scope.row.staffIdcard) }}
            </template>
          </el-table-column>
          <el-table-column label="电话" align="center" prop="staffPhone" />
          <el-table-column label="性别" align="center" prop="staffSex" />
          <el-table-column prop="" align="center" label="操作" v-if="!isMultiple">
            <template slot-scope="scope">
              <el-button type="primary" plain icon="el-icon-plus" size="mini"
                @click="handleAddStaff(scope.row)">选择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize" @pagination="getList" />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { listStaff } from "@/api/cld/staff";

export default {
  name: "SelectedStaff",
  dicts: ['cld_project_region', 'cld_project_post'],
  props: {
    // 是否显示项目信息
    isProject: {
      type: Boolean,
      default: true
    },
    projectId: {
      type: Number
    },
    notStaffIds: {
      type: Array
    },
    // 查询参数 （保单id  人员状态）
    params: {
      type: Object,
      default: {
        projectName: null,
        notStaffIds: null,
        isSetGroupProjectId: null
      }
    },
    // 操作组件类型
    type: {
      type: String
    },
    // 是否多选
    isMultiple: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员管理表格数据
      CldStaffList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        staffName: null,
        staffStatus: this.params?.staffStatus,
        insuranceId: this.params?.insuranceId,
        staffLevels: this.params?.staffLevels,
        params: this.params
      },
      options: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询人员管理列表 */
    getList() {
      this.loading = true;
      this.loading = true;
      listStaff(this.queryParams).then(response => {
        this.CldStaffList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.$emit('multipleInput', selection);
    },
    // 选择员工
    handleAddStaff(row) {
      this.$emit('childInput', row);
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>
